/* SPI Master example: jpeg decoder.

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/

/*
The image used for the effect on the LCD in the SPI master example is stored in flash
as a jpeg file. This file contains the decode_image routine, which uses the tiny JPEG
decoder library to decode this JPEG into a format that can be sent to the display.

Keep in mind that the decoder library cannot handle progressive files (will give
``Image decoder: jd_prepare failed (8)`` as an error) so make sure to save in the correct
format if you want to use a different image file.
*/

#include "decode_image.h"
#include "jpeg_decoder.h"
#include "esp_log.h"
#include "esp_check.h"
#include <string.h>
#include "freertos/FreeRTOS.h"

const char *TAG = "ImageDec";

//Reference the binary-included jpeg file
extern const uint8_t image_jpg_start[] asm("_binary_image_jpg_start");
extern const uint8_t image_jpg_end[] asm("_binary_image_jpg_end");
//Define the height and width of the jpeg file. Make sure this matches the actual jpeg
//dimensions.

uint16_t pixels[IMAGE_H * IMAGE_W];

static int32_t switch_tag = 0;
uint8_t jpg_buffer1[] = {0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x32,0x22,0x26,0x2c,0x26,0x1f,0x32,0x2c,0x29,0x2c,0x38,0x35,0x32,0x3b,0x4b,0x7d,0x51,0x4b,0x45,0x45,0x4b,0x99,0x6d,0x74,0x5b,0x7d,0xb5,0x9f,0xbf,0xbc,0xb2,0x9f,0xaf,0xac,0xc8,0xe1,0xff,0xf4,0xc8,0xd5,0xff,0xd8,0xac,0xaf,0xfa,0xff,0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xc2,0xf1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0x00,0x43,0x01,0x35,0x38,0x38,0x4b,0x42,0x4b,0x93,0x51,0x51,0x93,0xff,0xce,0xaf,0xce,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc4,0x00,0x1f,0x00,0x00,0x01,0x05,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,0xc4,0x00,0xb5,0x10,0x00,0x02,0x01,0x03,0x03,0x02,0x04,0x03,0x05,0x05,0x04,0x04,0x00,0x00,0x01,0x7d,0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xff,0xc4,0x00,0x1f,0x01,0x00,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,0xc4,0x00,0xb5,0x11,0x00,0x02,0x01,0x02,0x04,0x04,0x03,0x04,0x07,0x05,0x04,0x04,0x00,0x01,0x02,0x77,0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xff,0xc0,0x00,0x11,0x08,0x00,0xf0,0x00,0xf0,0x03,0x01,0x21,0x00,0x02,0x11,0x01,0x03,0x11,0x01,0xff,0xda,0x00,0x0c,0x03,0x01,0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0x45,0xe1,0xaa,0x6a,0x92,0x02,0x96,0x98,0x0a,0x29,0x69,0x08,0x4a,0x28,0x18,0x94,0x50,0x01,0x49,0x4c,0x41,0x49,0x40,0xc2,0x92,0x80,0x12,0x92,0x80,0x12,0x8a,0x00,0x4a,0x29,0x80,0x53,0xe1,0x1f,0x39,0xfa,0x50,0x22,0x59,0x3a,0x53,0x25,0xa4,0x04,0x74,0x62,0x98,0x06,0x29,0x68,0x02,0x3a,0x96,0x33,0x95,0xa4,0x31,0xf4,0xb4,0x80,0x5a,0x5a,0x04,0x25,0x14,0x0c,0x29,0x28,0x00,0xa4,0xa0,0x02,0x92,0x98,0x05,0x25,0x00,0x14,0x94,0x00,0x94,0x94,0x00,0x51,0x4c,0x41,0x52,0xdb,0xf4,0x63,0x48,0x07,0x3f,0xde,0x14,0x84,0x67,0x77,0xd2,0x80,0x21,0xa7,0x53,0x00,0xa2,0x80,0x23,0xa5,0x43,0x86,0xa4,0x51,0x35,0x2d,0x21,0x05,0x3a,0x80,0x0a,0x4a,0x00,0x29,0x28,0x00,0xa4,0xa0,0x02,0x92,0x80,0x0a,0x4a,0x60,0x25,0x25,0x00,0x14,0x94,0x00,0x51,0x40,0x05,0x4f,0x07,0xdc,0xa0,0x42,0xff,0x00,0xcb,0x4f,0xc2,0x84,0xe7,0x3e,0xe6,0x80,0x20,0x14,0xb4,0xc0,0x5a,0x28,0x02,0x3a,0x4a,0x91,0x92,0xa1,0xc8,0xa7,0xd0,0x01,0x4a,0x28,0x01,0x69,0x28,0x00,0xa4,0xa0,0x02,0x92,0x80,0x0a,0x4a,0x00,0x29,0x29,0x80,0x94,0x50,0x02,0x52,0x50,0x01,0x45,0x00,0x15,0x66,0x2f,0xf5,0x62,0x81,0x0d,0xfe,0xf9,0xa7,0x27,0x0a,0x28,0x11,0x0b,0x70,0xe6,0x8a,0x63,0x0a,0x5a,0x00,0x8e,0x9b,0x52,0x31,0xc8,0x7e,0x6a,0x96,0x80,0x16,0x96,0x80,0x16,0x92,0x80,0x0a,0x4a,0x00,0x29,0x28,0x00,0xa4,0xa6,0x01,0x49,0x40,0x09,0x49,0x40,0x09,0x45,0x00,0x14,0x50,0x01,0x57,0x31,0xb5,0x71,0xe9,0x40,0x88,0x4f,0x29,0xf5,0xa9,0x68,0x02,0x29,0x7f,0xd6,0x53,0x69,0x80,0x52,0xd0,0x04,0x54,0x52,0x18,0xda,0x92,0x36,0x2c,0x39,0xfa,0x50,0x04,0x94,0xb4,0x80,0x5a,0x28,0x01,0x29,0x28,0x00,0xa4,0xa0,0x04,0xa2,0x80,0x12,0x8a,0x00,0x4a,0x4a,0x60,0x25,0x14,0x00,0x51,0x40,0x0a,0x9f,0x7c,0x7d,0x6a,0xd3,0xf4,0x34,0x08,0x8b,0xfb,0xa2,0xa6,0x5a,0x42,0x23,0xb9,0xfb,0xeb,0xf4,0xa8,0xea,0x86,0x2d,0x2d,0x00,0x41,0x4c,0x2f,0x9e,0x94,0x86,0x20,0xab,0xb6,0xc9,0xb4,0x73,0xd1,0x39,0xfc,0x68,0x01,0xbd,0x79,0xf5,0xa2,0x90,0x0b,0x4b,0x40,0x0d,0xa2,0x80,0x12,0x8a,0x00,0x4a,0x28,0x01,0x28,0xa0,0x04,0xa4,0xa6,0x02,0x51,0x40,0x05,0x14,0xc4,0x3e,0x1f,0xf5,0x82,0xa6,0x93,0xee,0xd2,0x01,0xa3,0xef,0x55,0x88,0xc5,0x21,0x11,0x5d,0xfd,0xe4,0xa8,0xaa,0x86,0x2d,0x39,0x7a,0xd0,0x05,0x45,0xcd,0x38,0xae,0x7d,0xa8,0x01,0x22,0x5f,0x9f,0x9e,0xdc,0xd5,0x8b,0x83,0xb6,0x35,0x8b,0xb9,0xe5,0xa8,0x28,0x6a,0x9c,0x8a,0x75,0x48,0x85,0xa5,0xa0,0x06,0xd2,0x50,0x01,0x49,0x40,0x05,0x14,0x00,0x94,0x94,0x00,0x52,0x53,0x01,0x28,0xa0,0x02,0x90,0x9a,0x04,0x49,0x6f,0xf7,0xaa,0x47,0xa0,0x04,0x4e,0xb5,0x71,0x06,0x05,0x00,0x55,0x9f,0x99,0xcf,0xb7,0x14,0xca,0x63,0x16,0x9e,0x28,0x11,0x4c,0x53,0xe8,0x01,0xc8,0x70,0xe3,0x3d,0x3b,0xd1,0x2b,0x6f,0x94,0xb5,0x22,0x86,0xa9,0xc1,0xa9,0x69,0x08,0x5a,0x5a,0x00,0x43,0x49,0x40,0x05,0x25,0x00,0x14,0x94,0x00,0x52,0x50,0x01,0x49,0x4c,0x04,0xa2,0x80,0x06,0xa6,0xd3,0x11,0x2d,0xbf,0xfa,0xcf,0xc2,0xa5,0x7a,0x40,0x11,0x7f,0xad,0x15,0x72,0x82,0x91,0x9f,0x9d,0xcc,0x5b,0xd4,0xd3,0xa9,0x92,0x2d,0x3e,0x90,0xca,0x62,0x9d,0x4c,0x03,0xb5,0x14,0x80,0x4a,0x91,0x0e,0x56,0x90,0x0e,0xa5,0xa0,0x00,0xd2,0x50,0x01,0x45,0x00,0x25,0x14,0x00,0x94,0x50,0x02,0x52,0x50,0x01,0x45,0x30,0x1a,0xd4,0x94,0xc4,0x49,0x07,0xfa,0xe5,0xab,0x12,0x54,0x80,0x89,0xfe,0xb0,0x54,0xd7,0x07,0x10,0xb7,0xbf,0x14,0xd0,0xca,0x9d,0xe9,0xd4,0xc4,0x28,0xa7,0x52,0x19,0x56,0x93,0x75,0x30,0x01,0xcd,0x3f,0xbf,0xd6,0x80,0x12,0x84,0xe0,0xd4,0x8c,0x96,0x8a,0x04,0x2d,0x14,0x00,0x94,0x52,0x00,0xa4,0xa6,0x01,0x49,0x40,0x05,0x25,0x00,0x14,0x94,0x00,0x8d,0x4d,0xaa,0x10,0xf8,0xcf,0xce,0xbf,0x5a,0xb7,0x2f,0x4a,0x90,0x18,0x3e,0xf8,0xa5,0xbb,0x6e,0x55,0x3f,0x1a,0x68,0x64,0x34,0xea,0x04,0x3a,0x96,0x81,0x94,0x8d,0x36,0x98,0x87,0x21,0xa9,0x16,0x81,0x87,0xb5,0x18,0xa4,0x03,0xd7,0xa5,0x3a,0x90,0xc2,0x96,0x81,0x05,0x14,0x80,0x4a,0x29,0x80,0x52,0x50,0x02,0x51,0x40,0x09,0x49,0x40,0x08,0xf4,0x95,0x42,0x01,0x57,0xe5,0xe5,0x0d,0x48,0x11,0x0f,0xe1,0xa6,0x4a,0x77,0x4c,0x7f,0x2a,0x60,0x27,0x57,0xc7,0xb5,0x38,0xfd,0xef,0xc3,0x34,0xc0,0x29,0x69,0x0c,0xa3,0x49,0x4c,0x43,0x96,0xa6,0x5a,0x06,0x21,0x38,0x6a,0x7d,0x20,0x14,0x52,0xd4,0x80,0xb4,0x85,0x80,0xef,0x4c,0x06,0xac,0x99,0x3d,0x29,0xf4,0x00,0x94,0x50,0x02,0x51,0x40,0x09,0x49,0x40,0x09,0x45,0x30,0x1a,0xdd,0x69,0x29,0x88,0x5a,0xbf,0xd6,0x21,0xf4,0xa9,0x02,0x20,0x71,0x10,0x3e,0x95,0x12,0x50,0x03,0xa3,0xff,0x00,0x5a,0xb4,0xff,0x00,0xe2,0x5f,0xa5,0x30,0x1d,0x45,0x21,0x99,0x94,0xea,0xa0,0x1e,0xb5,0x28,0xa0,0x06,0x3f,0x5a,0x7a,0x1a,0x00,0x7d,0x33,0xcc,0xf4,0xe6,0xa4,0x06,0x97,0x63,0x4d,0xaa,0x10,0xe4,0x19,0x6c,0x55,0x99,0x47,0x29,0xf4,0xa4,0x32,0x3a,0x29,0x00,0x94,0x50,0x02,0x52,0x50,0x02,0x51,0x40,0x08,0xd4,0xda,0x62,0x14,0x75,0xab,0xb1,0x7f,0xa8,0x5a,0x00,0x8d,0xbf,0xd4,0x7f,0xc0,0xb1,0x4c,0xfe,0x1a,0x00,0x5e,0x9b,0x0f,0xbd,0x4c,0xe3,0xe7,0x1f,0x5a,0x00,0x5a,0x4a,0x91,0x99,0xb4,0x55,0x88,0x78,0xa7,0xad,0x03,0x12,0x5e,0xb4,0xa9,0xd2,0x80,0x10,0xf5,0xa2,0x80,0x12,0x96,0x90,0x89,0xad,0x53,0x2c,0x4d,0x3e,0x43,0xb9,0xcd,0x03,0x1b,0x49,0x48,0x02,0x92,0x80,0x12,0x8a,0x00,0x4a,0x4a,0x00,0x6b,0xd2,0x53,0x10,0x55,0xc8,0x3f,0xd5,0x7e,0x34,0x98,0x10,0xbf,0xdf,0xc5,0x1d,0x4d,0x00,0x2c,0x9c,0xab,0x63,0xb0,0xcd,0x4d,0x21,0xe3,0x3f,0x43,0x4c,0x64,0x84,0x52,0x54,0x01,0x97,0x4b,0x5a,0x08,0x5a,0x91,0x68,0x18,0xaf,0xf7,0x69,0x13,0xae,0x28,0x00,0x6f,0xbd,0x49,0x40,0x82,0x8a,0x40,0x5c,0x88,0x79,0x50,0xd4,0x55,0x23,0x0a,0x4a,0x00,0x29,0x29,0x80,0x94,0x94,0x00,0x52,0x50,0x02,0x35,0x32,0x98,0x82,0xac,0xc5,0xf7,0x4d,0x00,0x30,0x8f,0x9a,0x9c,0x83,0x9a,0x06,0x4d,0xe5,0x91,0x13,0x71,0xd6,0x99,0xd6,0xd9,0x7f,0xdd,0xc5,0x00,0x59,0x5f,0x99,0x41,0xa3,0x15,0x00,0x64,0x51,0x5a,0x08,0x70,0xa9,0x16,0x80,0x1d,0x4d,0xef,0x40,0xc1,0xba,0xd2,0x52,0x00,0xa5,0x8c,0x6e,0x7a,0x42,0x2e,0x4d,0xc6,0x17,0xf1,0xa8,0x68,0x18,0x52,0x52,0x00,0xa4,0xa6,0x02,0x52,0x50,0x01,0x4d,0xa0,0x04,0x6e,0x94,0xca,0x62,0x16,0xa7,0x87,0xd2,0x81,0x8f,0x61,0xf3,0x2f,0xd6,0xa5,0x81,0x76,0xbb,0x67,0xad,0x03,0x45,0x8a,0xa9,0x1f,0xfa,0xa2,0xbe,0x8f,0x4c,0x19,0x35,0xbf,0xfa,0x91,0x52,0xd4,0x58,0x2c,0x62,0x52,0xd5,0x88,0x72,0xd4,0x82,0x90,0x0b,0x40,0xa6,0x01,0x27,0x6a,0x6d,0x21,0x05,0x4f,0x6a,0xbd,0xe9,0x30,0x1e,0xe7,0x73,0x93,0x4c,0xa4,0x30,0xa4,0xa0,0x02,0x92,0x98,0x09,0x49,0x40,0x09,0x49,0x40,0x01,0xe9,0x51,0xd3,0x00,0xab,0x16,0xdf,0xeb,0x97,0xe9,0x40,0x16,0x25,0x4d,0xbb,0x4f,0xfb,0x42,0x9e,0x7f,0xe3,0xe5,0x3d,0x0a,0x9a,0x0a,0x24,0x35,0x5c,0x7f,0xac,0x9c,0x7d,0x1a,0x81,0x0f,0x83,0xa3,0x0f,0x7a,0x9a,0x98,0xd1,0x8b,0x45,0x04,0x8e,0x15,0x25,0x02,0x0a,0x70,0xa0,0x62,0x49,0xda,0x9b,0x48,0x42,0x55,0xd0,0x3c,0xb8,0xfe,0x82,0x80,0x22,0xa2,0xa4,0x62,0x51,0x40,0x09,0x49,0x4c,0x02,0x92,0x80,0x1b,0x45,0x00,0x07,0xa5,0x47,0x4c,0x41,0x53,0x41,0xfe,0xb1,0x3e,0xb4,0x0c,0xb7,0x78,0x7f,0x70,0x7d,0x7a,0xd2,0xcb,0xf7,0xe3,0x3e,0xf4,0xc6,0x48,0xfd,0x2a,0xbe,0x3f,0xd2,0xb1,0xfd,0xe4,0xa0,0x43,0xe0,0x3f,0x3b,0x7e,0x06,0xa7,0xa0,0xa4,0x62,0xd2,0xd0,0x48,0x2d,0x48,0x28,0x01,0x45,0x3e,0x80,0x18,0xfd,0x69,0x28,0x10,0xe8,0x97,0x7b,0x63,0xda,0xac,0xce,0xdf,0xaf,0x34,0x01,0x16,0xec,0xd1,0x52,0x31,0x28,0xa0,0x02,0x92,0x80,0x12,0x92,0x80,0x12,0x92,0x98,0x05,0x47,0x40,0x82,0xa5,0x43,0x8c,0x1f,0x4a,0x43,0x2e,0x5c,0x7c,0xca,0x47,0xb5,0x38,0x10,0xd6,0xe8,0xff,0x00,0x43,0x4c,0x09,0x1f,0xa5,0x55,0x6e,0x26,0x81,0xbe,0xa2,0x98,0x0f,0x8f,0x8b,0x8f,0xce,0xac,0xd0,0x52,0x31,0x69,0x68,0x20,0x51,0x52,0x52,0x00,0xa7,0x8a,0x63,0x18,0xdf,0x78,0xd3,0x7b,0xd2,0x11,0x62,0xd8,0x7f,0x17,0xb5,0x24,0xe7,0xe6,0x34,0x86,0x40,0x38,0x39,0xc5,0x3b,0x79,0xf4,0xa6,0x01,0xb8,0xd1,0xb9,0xbd,0x29,0x00,0x99,0x6a,0x32,0x68,0x01,0x32,0x69,0x33,0x4c,0x42,0x64,0xd1,0x48,0x02,0x92,0x98,0x05,0x3c,0x7d,0xd3,0x40,0x17,0xba,0xa0,0x34,0x90,0xff,0x00,0xc7,0xa1,0x1e,0x99,0x14,0x8a,0x26,0x3c,0xc7,0xf8,0x55,0x7b,0x8e,0x23,0x56,0xfe,0xeb,0x83,0x4c,0x42,0xb7,0xfa,0xf0,0x7d,0xea,0xd5,0x05,0x23,0x16,0x96,0x99,0x03,0x85,0x3a,0x81,0x8b,0x4e,0x14,0x08,0x6b,0xfd,0xe3,0x49,0xd5,0xa8,0x02,0xdc,0x7f,0x24,0x1f,0x41,0x55,0x9c,0xf6,0xef,0x52,0x31,0xab,0xd6,0x9d,0x8a,0x00,0x31,0x49,0xed,0x40,0x05,0x14,0x00,0x53,0x4d,0x00,0x27,0x02,0x92,0x81,0x06,0x45,0x36,0x98,0x05,0x3d,0x28,0x19,0x72,0x2f,0xf5,0x0b,0x4b,0x01,0xe2,0x41,0xef,0x40,0x0f,0x84,0xfe,0xe4,0x54,0x73,0xfc,0xd6,0xd2,0x0f,0x6a,0x60,0x24,0x8f,0x95,0x47,0xf5,0x5d,0xd5,0x72,0x91,0x48,0xc6,0xc5,0x14,0xc8,0x1c,0x29,0xc2,0x80,0x16,0x9d,0xda,0x80,0x1b,0x20,0x60,0x14,0xb7,0x7a,0x23,0x19,0x6f,0xc2,0x80,0x2d,0x5c,0x9c,0x28,0x5f,0x53,0x9a,0xaa,0xdf,0xeb,0x6a,0x46,0x1d,0x0f,0x14,0x64,0xfa,0x50,0x01,0x93,0x41,0xcd,0x00,0x02,0x93,0x9a,0x00,0x4a,0x4a,0x04,0x20,0xe9,0x4b,0x40,0x09,0x4d,0xa6,0x01,0x4e,0x4a,0x06,0x5c,0xb7,0xff,0x00,0x53,0xf4,0x34,0x91,0xff,0x00,0xac,0x90,0x7d,0x29,0x01,0x24,0x07,0xe4,0x23,0xde,0x86,0x19,0xdc,0xbe,0xa2,0xa8,0x08,0x53,0xe6,0xb4,0x53,0xf5,0x15,0x72,0x13,0xba,0x25,0x3e,0xd4,0x8a,0x32,0x68,0xa6,0x40,0xea,0x75,0x00,0x2d,0x0d,0xf7,0x29,0x0c,0x6e,0x72,0x7b,0x54,0xb6,0xc3,0x3f,0x8d,0x02,0x16,0xe1,0xbf,0xd2,0x4f,0xa0,0xe2,0xa3,0x1c,0xcd,0x40,0xc4,0x43,0x9c,0x9a,0x75,0x21,0x89,0xde,0x82,0x68,0x10,0x52,0x50,0x01,0x48,0x68,0x01,0xa3,0xa5,0x2d,0x30,0x12,0x98,0x7a,0xd0,0x02,0x53,0xd6,0x80,0x2d,0xda,0xfd,0xc7,0xfa,0xd2,0x7f,0xcb,0xcf,0xd5,0x4d,0x20,0x1f,0x0f,0xde,0x90,0x54,0x9f,0xc5,0x4c,0x08,0x22,0xcf,0x97,0x22,0xff,0x00,0x76,0x4a,0xb3,0x6b,0xfe,0xa7,0x1e,0x94,0x0d,0x19,0x74,0x53,0x24,0x70,0xa7,0x50,0x03,0xa8,0x7f,0xb9,0x40,0x11,0xd5,0xbb,0x7c,0x02,0x4f,0x65,0xa4,0x32,0xb9,0x24,0xb1,0x27,0xbd,0x22,0xfd,0xd9,0x28,0x01,0x14,0xe0,0x52,0xee,0xa0,0x03,0xbd,0x1d,0xa8,0x00,0x1d,0x28,0xa4,0x01,0x9a,0x43,0xd2,0x80,0x1a,0x29,0x73,0x40,0x09,0x9a,0x69,0xa6,0x03,0x69,0xe2,0x80,0x2c,0xdb,0x1f,0x9d,0x87,0xa8,0xa7,0x4b,0xc3,0xa9,0xf7,0xa4,0x02,0x42,0xc7,0xce,0xfa,0xad,0x4a,0x4f,0xf2,0xa6,0x04,0x79,0xc4,0xf3,0xaf,0xaa,0xee,0xa9,0xed,0x7f,0x8f,0xeb,0x40,0xcc,0xda,0x28,0x24,0x70,0xa7,0x53,0x01,0xd4,0x49,0xf7,0x68,0x01,0xab,0xf7,0xb3,0x56,0xbf,0xd5,0xda,0xfd,0x70,0x28,0x19,0x5b,0xf8,0x8d,0x37,0x3f,0x25,0x20,0x11,0x7a,0x53,0xa8,0x10,0x0a,0x4e,0x3b,0x8a,0x43,0x17,0xf8,0x69,0xbd,0xe8,0x10,0x0f,0xbe,0x29,0x58,0xf0,0xd4,0x14,0x32,0x8c,0xd0,0x21,0x3f,0x0a,0x43,0xf4,0xa0,0x04,0xa7,0x0a,0x60,0x58,0xb7,0xff,0x00,0x5c,0x2a,0x4b,0x8f,0xbb,0x9f,0x43,0x48,0x04,0xfb,0xb3,0x2d,0x4b,0x9c,0x30,0xa6,0x03,0x0e,0x3e,0xda,0xbc,0x7d,0xe5,0xc5,0x2d,0x99,0xfd,0xe6,0x3d,0x45,0x20,0x28,0xd1,0x54,0x21,0xe2,0x96,0x80,0x1f,0x4d,0x7e,0xa2,0x80,0x16,0x25,0xed,0x56,0x2e,0x78,0x64,0x4f,0x41,0x40,0xca,0xb4,0xa7,0x3f,0x85,0x20,0x00,0x7e,0xb4,0xaa,0x68,0x00,0x34,0x94,0x00,0xb9,0xe2,0x9b,0x40,0x84,0xc9,0x1c,0x8a,0x59,0x33,0xdd,0xc1,0xfa,0x1a,0x43,0x1b,0x45,0x00,0x25,0x23,0x50,0x03,0x29,0xc2,0xa8,0x09,0xe1,0xff,0x00,0x5a,0x9f,0x5a,0x9a,0xe7,0xfd,0x51,0xa9,0x01,0x0f,0x54,0x3f,0x4a,0x95,0xb8,0x34,0x0c,0x8a,0x7e,0x26,0x85,0xbd,0x0e,0x29,0xd1,0x7c,0xb7,0x5f,0x89,0x14,0x08,0xa5,0x45,0x50,0x0e,0x14,0xea,0x04,0x3c,0x53,0x1b,0xef,0xd0,0x04,0xd6,0xe3,0x91,0x4b,0x73,0xfe,0xbd,0xe8,0x19,0x5f,0xa0,0xa4,0x3d,0x69,0x00,0xea,0x4a,0x00,0x33,0x4b,0x9c,0x50,0x01,0x49,0x40,0x85,0x5d,0xb9,0xf9,0xba,0x7a,0xd4,0x65,0xbd,0x28,0x18,0xd0,0x71,0x4e,0xa0,0x02,0x90,0xf4,0xa0,0x06,0xd3,0x85,0x00,0x48,0x0e,0x18,0x1f,0x7a,0xb7,0x2f,0x20,0xd2,0x02,0x1c,0xe6,0xdd,0x4f,0xb5,0x58,0x93,0xa5,0x30,0x21,0xbb,0xff,0x00,0x8f,0x7c,0xfa,0x11,0x4b,0x9f,0xf4,0x8c,0xfb,0x83,0x48,0x0a,0x74,0xb5,0x42,0x1d,0x4e,0x14,0x08,0x78,0xa6,0x1f,0xf5,0x94,0x0c,0xb9,0x66,0x2a,0x3b,0xd1,0xfb,0xdf,0xaa,0xd2,0x28,0xae,0x69,0x9d,0xa8,0x10,0x9d,0xe9,0x73,0x40,0x09,0x9a,0x5a,0x60,0x19,0xf6,0xa2,0x90,0x83,0x35,0x1d,0x03,0x0a,0x5a,0x06,0x14,0x1a,0x04,0x25,0x28,0xa0,0x07,0xff,0x00,0x0d,0x5e,0x3f,0x74,0x1f,0x6a,0x40,0x42,0xbf,0xea,0x7f,0x13,0x53,0xaf,0x31,0xaf,0xd2,0x80,0x23,0x93,0x9b,0x67,0xf6,0xa8,0x73,0xf7,0x7f,0xdd,0xa0,0x08,0x29,0x7b,0xd5,0x08,0x75,0x38,0x50,0x03,0xc5,0x31,0x79,0x92,0x80,0x34,0xad,0xc7,0xc9,0x50,0xde,0x7d,0xe4,0x3f,0x5a,0x0a,0x2b,0x54,0x72,0xd2,0x01,0xb8,0xa5,0xc5,0x02,0x0c,0x52,0xe2,0x80,0x12,0x8c,0x50,0x03,0x48,0xa3,0x1c,0x50,0x03,0x45,0x38,0xd0,0x03,0x68,0x34,0xc0,0x4a,0x29,0x01,0x25,0x5c,0x8f,0x98,0x57,0xe9,0x48,0x06,0xc5,0xff,0x00,0x2d,0x07,0xa1,0xa7,0xc5,0xfe,0xa4,0x53,0x01,0x71,0x94,0x71,0xea,0x2a,0xa2,0xfd,0xd5,0x34,0x80,0xff,0xd9,};

uint8_t jpg_buffer2[] = {0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x32,0x22,0x26,0x2c,0x26,0x1f,0x32,0x2c,0x29,0x2c,0x38,0x35,0x32,0x3b,0x4b,0x7d,0x51,0x4b,0x45,0x45,0x4b,0x99,0x6d,0x74,0x5b,0x7d,0xb5,0x9f,0xbf,0xbc,0xb2,0x9f,0xaf,0xac,0xc8,0xe1,0xff,0xf4,0xc8,0xd5,0xff,0xd8,0xac,0xaf,0xfa,0xff,0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xc2,0xf1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0x00,0x43,0x01,0x35,0x38,0x38,0x4b,0x42,0x4b,0x93,0x51,0x51,0x93,0xff,0xce,0xaf,0xce,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc4,0x00,0x1f,0x00,0x00,0x01,0x05,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,0xc4,0x00,0xb5,0x10,0x00,0x02,0x01,0x03,0x03,0x02,0x04,0x03,0x05,0x05,0x04,0x04,0x00,0x00,0x01,0x7d,0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xff,0xc4,0x00,0x1f,0x01,0x00,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,0xc4,0x00,0xb5,0x11,0x00,0x02,0x01,0x02,0x04,0x04,0x03,0x04,0x07,0x05,0x04,0x04,0x00,0x01,0x02,0x77,0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xff,0xc0,0x00,0x11,0x08,0x00,0xf0,0x00,0xf0,0x03,0x01,0x21,0x00,0x02,0x11,0x01,0x03,0x11,0x01,0xff,0xda,0x00,0x0c,0x03,0x01,0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0x65,0x15,0x24,0x0b,0x4b,0x48,0x0a,0xa4,0xee,0x24,0xd0,0xab,0x93,0x54,0x32,0x4f,0xba,0x28,0x12,0x29,0xeb,0xc5,0x02,0x25,0x18,0xf5,0xa1,0x85,0x21,0x91,0xe2,0x93,0x65,0x30,0x10,0xa5,0x37,0x6d,0x00,0x34,0xd1,0x40,0xc7,0xa9,0xed,0x56,0x51,0xb3,0xc7,0x7a,0x42,0x1d,0x4b,0x40,0x84,0xa5,0xa0,0x02,0x9b,0x40,0x09,0x45,0x00,0x25,0x36,0x81,0x09,0x4d,0xa0,0x63,0xe9,0x69,0x00,0x51,0x40,0xc8,0x64,0x5c,0x1f,0xad,0x28,0xf9,0x45,0x30,0x10,0x82,0xdd,0x7a,0xd3,0xb6,0x0f,0x4a,0x60,0x29,0x89,0x7b,0x0c,0x52,0x6c,0x91,0x7e,0xe3,0xfe,0x74,0x80,0x0b,0x38,0xfb,0xeb,0xf9,0x51,0xbc,0x7d,0x28,0x01,0xd4,0x62,0x80,0x1a,0xc8,0x0f,0x6a,0x61,0x18,0xa0,0x06,0x54,0xc0,0xf4,0xa0,0x64,0xea,0xdb,0x85,0x3a,0x91,0x22,0x51,0x4c,0x05,0xa4,0xa0,0x06,0xd1,0x40,0x09,0x4d,0xa0,0x04,0xa4,0xa0,0x43,0xe8,0xa0,0x61,0x4b,0x48,0x63,0x1b,0xb5,0x33,0xaf,0xf4,0xa6,0x21,0xde,0xb8,0xed,0x4f,0x39,0x07,0xa5,0x30,0x17,0x34,0xb4,0x86,0x2e,0x29,0x1e,0x3c,0xf6,0xa4,0x04,0x46,0x3c,0x1e,0x29,0x73,0xcf,0x22,0x81,0x0e,0x14,0x92,0x0e,0x29,0x8c,0x81,0x87,0x14,0xe8,0xfa,0x53,0x01,0xe0,0xe0,0xe4,0x54,0xc0,0xe4,0x66,0x90,0x85,0xa2,0x80,0x0a,0x28,0x01,0x0d,0x25,0x00,0x25,0x36,0x80,0x1b,0x49,0x40,0x0f,0xa5,0xa4,0x30,0xa5,0xa0,0x44,0x64,0xe4,0xe3,0xdf,0x14,0x63,0xd0,0xd5,0x00,0x9f,0x74,0x7d,0x69,0xf8,0xa0,0x07,0x81,0x4e,0x02,0x90,0x12,0x01,0x41,0x14,0x86,0x34,0xad,0x33,0xc9,0xc8,0xa0,0x06,0x00,0xc1,0xb6,0xf5,0xf4,0xa7,0xe0,0x0e,0xa7,0x1e,0xf4,0x01,0x04,0xaa,0x41,0xc5,0x32,0x3f,0xbd,0x8a,0x60,0x49,0x4a,0xad,0xb4,0xfb,0x52,0x11,0x35,0x14,0xc6,0x14,0x50,0x20,0xa6,0xd0,0x03,0x69,0xb4,0x00,0x94,0xda,0x06,0x49,0x4b,0x48,0x41,0x48,0xcd,0x8e,0x9d,0x69,0x8c,0x89,0x41,0xf3,0x09,0xfd,0x69,0xfd,0xfd,0xa8,0x01,0x40,0xee,0x69,0xcb,0x4c,0x44,0x82,0x9c,0x29,0x00,0xf1,0x4f,0xa4,0x31,0x76,0xd2,0xb0,0xf9,0x68,0x02,0xb9,0xe0,0x13,0x4c,0xeb,0x40,0xc8,0xe6,0xfe,0x0f,0xa5,0x43,0x1f,0xfa,0xda,0x60,0x4c,0x69,0x9f,0xad,0x21,0x0f,0x8d,0xb1,0xc1,0x3c,0x54,0xb4,0xc4,0x25,0x14,0x00,0x52,0x1a,0x00,0x69,0xa6,0xd0,0x03,0x69,0x28,0x02,0x5a,0x29,0x00,0x54,0x6b,0xf3,0x31,0x6a,0x06,0x4b,0x8a,0x31,0xed,0x4c,0x04,0xa7,0x0a,0x60,0x3c,0x53,0x85,0x21,0x0f,0x14,0xfa,0x91,0x8e,0xa7,0x37,0xdd,0xa0,0x0a,0x73,0x11,0xf7,0x69,0x91,0x0e,0x6a,0x86,0x12,0x8e,0x54,0x7a,0x0a,0xae,0x06,0x27,0xc5,0x02,0x26,0xa6,0x9a,0x42,0x1b,0x52,0x46,0xdd,0xa8,0x18,0xfa,0x4a,0x60,0x14,0x50,0x21,0xa6,0x99,0x40,0x09,0x49,0x40,0x12,0xd1,0x48,0x63,0x64,0x19,0x5f,0xc6,0x9a,0x3e,0x5f,0xa5,0x31,0x0f,0x62,0xc5,0x7e,0x42,0x05,0x38,0x31,0xd9,0x86,0xeb,0x40,0x06,0x29,0xc0,0x50,0x03,0xe9,0xe2,0x80,0x1c,0x29,0xe2,0xa4,0x63,0x85,0x39,0xbe,0xe1,0xa0,0x0a,0x48,0x9c,0x63,0xad,0x4d,0x14,0x43,0x39,0x34,0xc6,0x57,0x9f,0xfd,0x61,0xaa,0xe3,0x9b,0x8f,0xc2,0x98,0x89,0x69,0x28,0x01,0xb4,0xda,0x04,0x4a,0x8d,0x9f,0xad,0x38,0x9d,0xa3,0x27,0xa5,0x03,0x11,0x0e,0xf1,0x95,0xe6,0x8a,0x00,0x0d,0x32,0x81,0x09,0x49,0x48,0x09,0x28,0xa0,0x02,0x9b,0x83,0xd3,0xf3,0xa0,0x04,0xc6,0xd2,0x69,0xff,0x00,0x2d,0x30,0x1c,0x29,0xf4,0x00,0xea,0x70,0xa0,0x09,0x05,0x3c,0x52,0x01,0xc2,0x87,0x5c,0x8a,0x91,0x8d,0xf2,0xa8,0x3f,0x2d,0x03,0x28,0xcb,0xdc,0xd4,0x30,0x8f,0xbc,0xc6,0xac,0x44,0xb4,0x94,0x80,0x4a,0x69,0xa0,0x06,0x67,0x1c,0xd3,0x59,0x8b,0x9e,0x69,0xa0,0x2d,0x59,0xf1,0x1e,0xec,0x76,0x26,0x9b,0xd2,0x80,0x0a,0x69,0xa0,0x41,0x49,0x48,0x07,0xd1,0x40,0xc2,0x96,0x80,0x23,0x6f,0xbf,0x4e,0x08,0x69,0x80,0xf5,0x40,0x29,0xc2,0x81,0x0e,0xa7,0x8a,0x06,0x3c,0x54,0x82,0xa4,0x43,0xc5,0x3e,0x90,0xc2,0xa1,0xb8,0x38,0x4a,0x00,0xce,0x98,0xfc,0x86,0x92,0x21,0xfb,0xb1,0x56,0x03,0xa8,0xa4,0x02,0x54,0x6e,0xf8,0xe9,0xc9,0xa0,0x08,0xb3,0x9e,0xa6,0x8a,0xa0,0x2e,0xa8,0xf2,0xed,0x7a,0x7b,0x53,0x28,0x01,0x29,0x29,0x08,0x29,0x28,0x18,0xfa,0x29,0x08,0x29,0x68,0x18,0xc6,0xfb,0xd4,0xe1,0x40,0x0f,0x14,0xea,0x62,0x16,0x9c,0x29,0x0c,0x7d,0x38,0x1a,0x40,0x3b,0x35,0x28,0x34,0x80,0x75,0x57,0xbb,0xfb,0xb4,0x0c,0xce,0x9b,0x92,0x10,0x77,0xa9,0x2a,0x84,0x14,0xd6,0x21,0x7a,0x9a,0x00,0x85,0xa4,0x27,0xda,0x99,0x54,0x01,0x4b,0x4c,0x0b,0x97,0x07,0x6c,0x71,0xfd,0x6a,0x3a,0x80,0x12,0x8a,0x62,0x0a,0x4a,0x40,0x3f,0x14,0x50,0x01,0x4b,0x48,0x63,0x5b,0x91,0x40,0xaa,0x02,0x41,0x4f,0x14,0x08,0x75,0x14,0x86,0x19,0xa5,0xcd,0x21,0x8e,0x15,0x2a,0xd2,0x11,0x35,0x57,0xbb,0xfb,0xa2,0x80,0x33,0xc7,0x33,0x93,0xe9,0x52,0x55,0x01,0x0b,0x4b,0xfd,0xda,0x87,0xaf,0x24,0xe6,0x98,0x0b,0x8c,0xd4,0x9e,0x58,0xf7,0xfc,0xe9,0x80,0x6c,0xf7,0x14,0xdd,0x84,0x53,0x02,0xdc,0xe3,0x31,0x46,0xd5,0x15,0x40,0x85,0xa4,0xa0,0x02,0x9b,0x40,0x12,0xd1,0x40,0xc4,0xa2,0x80,0x12,0x93,0xa5,0x00,0x28,0x34,0xf0,0xd4,0xc0,0x76,0x68,0xcd,0x48,0x0b,0x4e,0xa0,0x07,0x54,0x8b,0x40,0x89,0xc7,0x4a,0x8a,0xe4,0x7e,0xef,0xe9,0x48,0xa3,0x2d,0x5b,0x8f,0xad,0x46,0x49,0xaa,0x10,0x94,0x9d,0x2a,0x80,0x33,0x4f,0xfa,0x9a,0x60,0x2e,0x69,0xe3,0x83,0x40,0x07,0x4e,0x45,0x39,0x48,0x61,0x91,0x52,0x01,0x45,0x21,0x05,0x25,0x03,0x24,0xa2,0x90,0x82,0x8c,0x53,0x18,0x94,0xd2,0x28,0x02,0x3c,0xd3,0xc3,0x50,0x03,0xf7,0x53,0x96,0x90,0x0f,0x14,0xea,0x62,0x0a,0x91,0x68,0x02,0xc2,0x1a,0x18,0x6e,0x52,0x2a,0x0a,0x31,0x4a,0x30,0x3b,0x48,0xe4,0x53,0x71,0x5a,0x08,0x69,0x3d,0xa9,0x29,0x80,0xab,0xd7,0x34,0x85,0xb2,0x69,0x8c,0x91,0x6a,0x4a,0x42,0x02,0x69,0x31,0xdc,0x0f,0xad,0x31,0x0b,0xbf,0x07,0x93,0xd6,0x9d,0x48,0x02,0x92,0x90,0x12,0x51,0x48,0x61,0x45,0x02,0x0a,0x29,0x0c,0x42,0x3d,0xa9,0xbb,0x05,0x00,0x34,0xae,0x2a,0x58,0xfa,0x53,0x02,0x4a,0x5a,0x62,0x0a,0x70,0x34,0x80,0x91,0x5f,0x14,0x49,0x74,0x10,0x7a,0xd2,0x19,0x94,0x49,0x72,0x59,0xfb,0xf3,0x4d,0x2d,0x5a,0x0c,0x6d,0x14,0x80,0x53,0xe9,0x49,0x40,0x12,0xad,0x49,0xda,0x82,0x48,0x4b,0x53,0xd4,0x93,0xd3,0xad,0x31,0x8f,0xdb,0xb9,0x7b,0x54,0x4a,0xdb,0x68,0x11,0x29,0x60,0x2a,0x16,0x3b,0xa9,0x0c,0xb3,0xba,0x9d,0x52,0x01,0x45,0x00,0x14,0x52,0x00,0xa4,0xa0,0x02,0x90,0x71,0x4c,0x44,0x82,0x96,0xa8,0x02,0x8c,0xd2,0x10,0x16,0xaa,0xae,0xf9,0xa6,0x32,0x22,0x73,0x49,0x41,0x42,0x51,0x4c,0x04,0xa7,0x50,0x03,0xd7,0xad,0x39,0xb6,0xd2,0x11,0x11,0xa7,0x47,0x40,0x13,0xf6,0xa8,0x65,0xeb,0x9a,0x62,0x12,0x33,0xdb,0x14,0x30,0xc1,0xf6,0xa0,0x65,0xbc,0x51,0x8a,0x80,0x0a,0x28,0x00,0xa2,0x90,0x05,0x25,0x30,0x0a,0x4e,0xf4,0x00,0xe0,0x69,0xd5,0x42,0x12,0x92,0x81,0x15,0xde,0x5d,0xe7,0x03,0xee,0xff,0x00,0x3a,0x8e,0x82,0x86,0xd1,0x4c,0x61,0x45,0x20,0x0a,0x5a,0x62,0x24,0x14,0x84,0xf1,0x40,0x88,0xe9,0xeb,0xd6,0x81,0x93,0x66,0x90,0x80,0xdd,0x68,0x11,0x03,0x0d,0xad,0x4f,0x53,0xbb,0x83,0x40,0xcb,0x54,0x54,0x00,0x51,0x40,0x05,0x14,0x80,0x29,0x29,0x80,0x53,0x5a,0x80,0x14,0x53,0xaa,0x84,0x2d,0x56,0x92,0x4d,0xfc,0x29,0xf9,0x7f,0x9d,0x00,0x45,0x49,0x41,0x41,0x45,0x30,0x12,0x8a,0x00,0x5a,0x75,0x20,0x0a,0x43,0x4c,0x42,0xad,0x2d,0x20,0x1f,0xde,0x9c,0x29,0x88,0x6b,0xd4,0x74,0x86,0x5c,0xa2,0xa4,0x41,0x45,0x00,0x14,0x52,0x18,0x94,0x99,0xa0,0x02,0x8a,0x04,0x20,0xa7,0x55,0x01,0x04,0xb2,0x6f,0xf9,0x57,0xa7,0xf3,0xa8,0xa9,0x94,0x14,0x94,0x00,0x52,0x53,0x00,0xa2,0x80,0x1d,0x45,0x21,0x09,0x45,0x31,0x8e,0x14,0xb4,0x84,0x14,0xf5,0xa6,0x02,0x37,0x4a,0x8f,0xbd,0x00,0x5d,0xa2,0xa0,0x02,0x8a,0x04,0x14,0x50,0x30,0xa4,0x34,0x80,0x4e,0x83,0x26,0xa1,0x79,0xb2,0x30,0x94,0xc0,0x97,0xa0,0xa8,0x65,0x93,0x3f,0x28,0xe9,0xfc,0xe9,0x81,0x1d,0x14,0xc6,0x25,0x14,0x00,0x94,0x53,0x00,0xed,0x40,0xa0,0x05,0xa2,0x81,0x05,0x2d,0x20,0x16,0x9d,0x4c,0x04,0xa7,0x0a,0x00,0x6b,0x1a,0x41,0xd6,0x90,0x17,0x28,0xa9,0x00,0xa2,0x90,0x05,0x14,0xc0,0x63,0xc8,0x13,0xeb,0xe9,0x51,0x19,0xcf,0x61,0x4d,0x01,0x1f,0xcd,0x2b,0x75,0xa9,0xf1,0x1c,0x5d,0x69,0x81,0x03,0x48,0x5f,0xaf,0x4f,0x4a,0x6d,0x31,0x85,0x14,0x00,0x51,0x48,0x04,0xa2,0x80,0x0a,0x28,0x01,0x68,0xa6,0x01,0x4b,0x48,0x05,0xa5,0x14,0x08,0x28,0xcd,0x00,0x25,0x28,0xa6,0x05,0xba,0x2a,0x00,0x29,0x29,0x08,0x29,0x71,0x4c,0x0a,0x6c,0xdb,0xdb,0x34,0xda,0xb2,0x89,0x10,0xed,0x56,0x6e,0xf4,0xce,0x5b,0xe6,0x34,0x80,0x4a,0x28,0x00,0xa2,0x80,0x12,0x8a,0x60,0x14,0x50,0x01,0x45,0x20,0x16,0x8a,0x60,0x25,0x2d,0x20,0x16,0x96,0x98,0x82,0x8a,0x00,0x29,0x68,0x02,0xdd,0x15,0x02,0x10,0xd3,0x33,0x40,0xc5,0x43,0xf3,0x53,0x67,0x93,0xf8,0x01,0xfa,0xd3,0x02,0xb5,0x15,0x43,0x0a,0x4a,0x00,0x5a,0x28,0x01,0x28,0xa0,0x02,0x8a,0x00,0x28,0xa0,0x02,0x8a,0x00,0x29,0x68,0x01,0x29,0x69,0x00,0xb4,0x94,0xc0,0x5a,0x28,0x10,0x53,0xa8,0x02,0xdd,0x15,0x02,0x1a,0x6a,0x33,0x40,0x0c,0xdd,0xb7,0xa7,0x5a,0x8a,0xa8,0xa0,0xa2,0x80,0x0a,0x4a,0x60,0x14,0xb4,0x00,0x94,0x52,0x00,0xa2,0x80,0x12,0x96,0x98,0x05,0x14,0x80,0x5a,0x4a,0x00,0x28,0xa0,0x05,0xa2,0x80,0x0a,0x5a,0x62,0x0a,0x5a,0x40,0x5b,0xa2,0xa4,0x43,0x5a,0xab,0xbb,0xfa,0x53,0x43,0x19,0x49,0x4c,0xa0,0xa5,0xa0,0x42,0x51,0x4c,0x02,0x8a,0x00,0x28,0xa0,0x02,0x8a,0x00,0x29,0x28,0x00,0xa5,0xa0,0x02,0x92,0x80,0x16,0x8a,0x00,0x5a,0x4a,0x00,0x75,0x14,0x08,0x4a,0x28,0x19,0x76,0x92,0xa4,0x92,0xbc,0xaf,0x9e,0x01,0xf9,0x7f,0x9d,0x47,0x4c,0xa1,0x28,0xa6,0x01,0x45,0x00,0x14,0x50,0x01,0x45,0x00,0x14,0x50,0x01,0x49,0x40,0x05,0x14,0x00,0xb4,0x52,0x01,0x28,0xa6,0x01,0x45,0x03,0x16,0x8a,0x04,0x2d,0x19,0xa0,0x41,0x45,0x00,0x5c,0xa6,0xb9,0xc2,0x1a,0x91,0x15,0x69,0x29,0x94,0x14,0x53,0x00,0xa2,0x90,0x05,0x14,0x0c,0x29,0x29,0x80,0x52,0xd0,0x21,0x28,0xa0,0x02,0x8a,0x00,0x28,0xa0,0x61,0x45,0x21,0x05,0x2d,0x00,0x14,0x53,0x00,0xa2,0x81,0x0b,0x49,0x40,0xcb,0xb5,0x0c,0xed,0xc0,0x5f,0x5e,0x6a,0x49,0x20,0xa2,0xa8,0xa0,0xa2,0x81,0x85,0x14,0x84,0x14,0x50,0x02,0x52,0xd3,0x01,0x28,0xa0,0x02,0x8a,0x00,0x28,0xa4,0x01,0x45,0x00,0x14,0x50,0x01,0x4b,0x4c,0x61,0x45,0x21,0x05,0x14,0xc0,0x28,0xa0,0x0b,0x95,0x55,0x9b,0x2c,0x4d,0x4a,0x24,0x6d,0x15,0x45,0x85,0x25,0x02,0x16,0x8a,0x00,0x28,0xa0,0x02,0x8a,0x00,0x29,0x28,0x00,0xa2,0x81,0x85,0x14,0x00,0x51,0x48,0x41,0x45,0x30,0x0a,0x5a,0x40,0x25,0x2d,0x30,0x0a,0x29,0x00,0xb4,0x94,0xc0,0x9e,0x47,0xdb,0xc0,0xeb,0xfc,0xaa,0x0a,0x42,0x41,0xcd,0x14,0xca,0x0a,0x28,0x10,0x51,0x40,0x05,0x25,0x00,0x2d,0x25,0x03,0x0a,0x5a,0x04,0x25,0x14,0x00,0x51,0x40,0x05,0x14,0x00,0x51,0x40,0x0b,0x49,0x40,0x05,0x2d,0x20,0x0a,0x29,0x88,0x28,0xa0,0x03,0xde,0x8a,0x43,0x0a,0x4a,0x63,0x16,0x8a,0x04,0x14,0x52,0x00,0xa2,0x98,0x09,0x45,0x03,0x16,0x92,0x80,0x0a,0x28,0x10,0x51,0x40,0xc2,0x8a,0x00,0x4a,0x5a,0x04,0x19,0xa2,0x80,0x16,0x92,0x80,0x0a,0x28,0x00,0xa5,0xa0,0x0f,0xff,0xd9,}; 
 


//Grab a rgb16 pixel from the esp32_tiles image
static inline uint16_t get_bgnd_pixel(int x, int y)
{
    //Get color of the pixel on x,y coords
    return (uint16_t) * (pixels + (y * IMAGE_W) + x);
}

//Instead of calculating the offsets for each pixel we grab, we pre-calculate the valueswhenever a frame changes, then re-use
//these as we go through all the pixels in the frame. This is much, much faster.
static int8_t xofs[240], yofs[240];
static int8_t xcomp[240], ycomp[240];

//Calculate the pixel data for a set of lines (with implied line size of 320). Pixels go in dest, line is the Y-coordinate of the
//first line to be calculated, linect is the amount of lines to calculate. Frame increases by one every time the entire image
//is displayed; this is used to go to the next frame of animation.
void decode_calc_lines(uint16_t *dest, int line, int frame, int linect)
{
    for (int y = line; y < line + linect; y++) {
        for (int x = 0; x < 240; x++) {
            *dest++ = get_bgnd_pixel(x + yofs[y] + xcomp[x], y + xofs[x] + ycomp[y]);
        }
    }
}

//Decode the embedded image into pixel lines that can be used with the rest of the logic.
static esp_err_t decode_jpeg(uint16_t *pixels, uint8_t *jpeg_data, uint32_t jpeg_len)
{
    esp_err_t ret = ESP_OK;
    esp_jpeg_image_output_t outimg;

    if(!pixels || !jpeg_data || !jpeg_len)
	    return ESP_ERR_INVALID_ARG;

    //JPEG decode config
    esp_jpeg_image_cfg_t jpeg_cfg = {
        .indata = (uint8_t *)jpeg_data,
        .indata_size = jpeg_len,
        .outbuf = (uint8_t*)(pixels),
        .outbuf_size = IMAGE_W * IMAGE_H * sizeof(uint16_t),
        .out_format = JPEG_IMAGE_FORMAT_RGB565,
        .out_scale = JPEG_IMAGE_SCALE_0,
        .flags = {
            .swap_color_bytes = 1,
        }
    };

    //JPEG decode
    esp_jpeg_decode(&jpeg_cfg, &outimg);

    //ESP_LOGI(TAG, "JPEG image decoded! Size of the decoded image is: %dpx x %dpx", outimg.width, outimg.height);

    return ret;
}

esp_err_t decode_image(uint8_t *jpeg_data, uint32_t jpeg_len)
{
    return decode_jpeg(pixels, jpeg_data, jpeg_len);
}
